import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout/index.vue'

export const constantRoutes = [

  {
    path: '/404',
    name:'404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
      path: '/',
      component: Layout,
      redirect: '/index',
      children: [{
        path: '/index',
        name: 'index',
        component: () => import('@/views/index/index'),
      }, {
        path: '/news',
        name: 'news',
        component: () => import('@/views/news/index'),
      }, {
        path: '/detail',
        name: 'detail',
        component: () => import('@/views/detail/index'),
      }]
},
{
      path: '*',
      redirect: '/404',
      hidden: true
},
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
